(0) Obligation:

The Runtime Complexity (innermost) of the given CpxTRS could be proven to be BOUNDS(1, n^1).


The TRS R consists of the following rules:

ge(x, 0) → true
ge(0, s(x)) → false
ge(s(x), s(y)) → ge(x, y)
minus(x, 0) → x
minus(s(x), s(y)) → minus(x, y)
div(x, y) → ify(ge(y, s(0)), x, y)
ify(false, x, y) → divByZeroError
ify(true, x, y) → if(ge(x, y), x, y)
if(false, x, y) → 0
if(true, x, y) → s(div(minus(x, y), y))

Rewrite Strategy: INNERMOST

(1) TrsToWeightedTrsProof (BOTH BOUNDS(ID, ID) transformation)

Transformed TRS to weighted TRS

(2) Obligation:

The Runtime Complexity (innermost) of the given CpxWeightedTrs could be proven to be BOUNDS(1, n^1).


The TRS R consists of the following rules:

ge(x, 0) → true [1]
ge(0, s(x)) → false [1]
ge(s(x), s(y)) → ge(x, y) [1]
minus(x, 0) → x [1]
minus(s(x), s(y)) → minus(x, y) [1]
div(x, y) → ify(ge(y, s(0)), x, y) [1]
ify(false, x, y) → divByZeroError [1]
ify(true, x, y) → if(ge(x, y), x, y) [1]
if(false, x, y) → 0 [1]
if(true, x, y) → s(div(minus(x, y), y)) [1]

Rewrite Strategy: INNERMOST

(3) TypeInferenceProof (BOTH BOUNDS(ID, ID) transformation)

Infered types.

(4) Obligation:

Runtime Complexity Weighted TRS with Types.
The TRS R consists of the following rules:

ge(x, 0) → true [1]
ge(0, s(x)) → false [1]
ge(s(x), s(y)) → ge(x, y) [1]
minus(x, 0) → x [1]
minus(s(x), s(y)) → minus(x, y) [1]
div(x, y) → ify(ge(y, s(0)), x, y) [1]
ify(false, x, y) → divByZeroError [1]
ify(true, x, y) → if(ge(x, y), x, y) [1]
if(false, x, y) → 0 [1]
if(true, x, y) → s(div(minus(x, y), y)) [1]

The TRS has the following type information:
ge :: 0:s:divByZeroError → 0:s:divByZeroError → true:false
0 :: 0:s:divByZeroError
true :: true:false
s :: 0:s:divByZeroError → 0:s:divByZeroError
false :: true:false
minus :: 0:s:divByZeroError → 0:s:divByZeroError → 0:s:divByZeroError
div :: 0:s:divByZeroError → 0:s:divByZeroError → 0:s:divByZeroError
ify :: true:false → 0:s:divByZeroError → 0:s:divByZeroError → 0:s:divByZeroError
divByZeroError :: 0:s:divByZeroError
if :: true:false → 0:s:divByZeroError → 0:s:divByZeroError → 0:s:divByZeroError

Rewrite Strategy: INNERMOST

(5) CompletionProof (UPPER BOUND(ID) transformation)

The TRS is a completely defined constructor system, as every type has a constant constructor and the following rules were added:

ge(v0, v1) → null_ge [0]
minus(v0, v1) → null_minus [0]
ify(v0, v1, v2) → null_ify [0]
if(v0, v1, v2) → null_if [0]

And the following fresh constants:

null_ge, null_minus, null_ify, null_if

(6) Obligation:

Runtime Complexity Weighted TRS where all functions are completely defined. The underlying TRS is:

Runtime Complexity Weighted TRS with Types.
The TRS R consists of the following rules:

ge(x, 0) → true [1]
ge(0, s(x)) → false [1]
ge(s(x), s(y)) → ge(x, y) [1]
minus(x, 0) → x [1]
minus(s(x), s(y)) → minus(x, y) [1]
div(x, y) → ify(ge(y, s(0)), x, y) [1]
ify(false, x, y) → divByZeroError [1]
ify(true, x, y) → if(ge(x, y), x, y) [1]
if(false, x, y) → 0 [1]
if(true, x, y) → s(div(minus(x, y), y)) [1]
ge(v0, v1) → null_ge [0]
minus(v0, v1) → null_minus [0]
ify(v0, v1, v2) → null_ify [0]
if(v0, v1, v2) → null_if [0]

The TRS has the following type information:
ge :: 0:s:divByZeroError:null_minus:null_ify:null_if → 0:s:divByZeroError:null_minus:null_ify:null_if → true:false:null_ge
0 :: 0:s:divByZeroError:null_minus:null_ify:null_if
true :: true:false:null_ge
s :: 0:s:divByZeroError:null_minus:null_ify:null_if → 0:s:divByZeroError:null_minus:null_ify:null_if
false :: true:false:null_ge
minus :: 0:s:divByZeroError:null_minus:null_ify:null_if → 0:s:divByZeroError:null_minus:null_ify:null_if → 0:s:divByZeroError:null_minus:null_ify:null_if
div :: 0:s:divByZeroError:null_minus:null_ify:null_if → 0:s:divByZeroError:null_minus:null_ify:null_if → 0:s:divByZeroError:null_minus:null_ify:null_if
ify :: true:false:null_ge → 0:s:divByZeroError:null_minus:null_ify:null_if → 0:s:divByZeroError:null_minus:null_ify:null_if → 0:s:divByZeroError:null_minus:null_ify:null_if
divByZeroError :: 0:s:divByZeroError:null_minus:null_ify:null_if
if :: true:false:null_ge → 0:s:divByZeroError:null_minus:null_ify:null_if → 0:s:divByZeroError:null_minus:null_ify:null_if → 0:s:divByZeroError:null_minus:null_ify:null_if
null_ge :: true:false:null_ge
null_minus :: 0:s:divByZeroError:null_minus:null_ify:null_if
null_ify :: 0:s:divByZeroError:null_minus:null_ify:null_if
null_if :: 0:s:divByZeroError:null_minus:null_ify:null_if

Rewrite Strategy: INNERMOST

(7) CpxTypedWeightedTrsToRntsProof (UPPER BOUND(ID) transformation)

Transformed the TRS into an over-approximating RNTS by (improved) Size Abstraction.
The constant constructors are abstracted as follows:

0 => 0
true => 2
false => 1
divByZeroError => 1
null_ge => 0
null_minus => 0
null_ify => 0
null_if => 0

(8) Obligation:

Complexity RNTS consisting of the following rules:

div(z, z') -{ 1 }→ ify(ge(y, 1 + 0), x, y) :|: x >= 0, y >= 0, z = x, z' = y
ge(z, z') -{ 1 }→ ge(x, y) :|: z' = 1 + y, x >= 0, y >= 0, z = 1 + x
ge(z, z') -{ 1 }→ 2 :|: x >= 0, z = x, z' = 0
ge(z, z') -{ 1 }→ 1 :|: z' = 1 + x, x >= 0, z = 0
ge(z, z') -{ 0 }→ 0 :|: v0 >= 0, v1 >= 0, z = v0, z' = v1
if(z, z', z'') -{ 1 }→ 0 :|: z' = x, z'' = y, z = 1, x >= 0, y >= 0
if(z, z', z'') -{ 0 }→ 0 :|: v0 >= 0, z'' = v2, v1 >= 0, z = v0, z' = v1, v2 >= 0
if(z, z', z'') -{ 1 }→ 1 + div(minus(x, y), y) :|: z = 2, z' = x, z'' = y, x >= 0, y >= 0
ify(z, z', z'') -{ 1 }→ if(ge(x, y), x, y) :|: z = 2, z' = x, z'' = y, x >= 0, y >= 0
ify(z, z', z'') -{ 1 }→ 1 :|: z' = x, z'' = y, z = 1, x >= 0, y >= 0
ify(z, z', z'') -{ 0 }→ 0 :|: v0 >= 0, z'' = v2, v1 >= 0, z = v0, z' = v1, v2 >= 0
minus(z, z') -{ 1 }→ x :|: x >= 0, z = x, z' = 0
minus(z, z') -{ 1 }→ minus(x, y) :|: z' = 1 + y, x >= 0, y >= 0, z = 1 + x
minus(z, z') -{ 0 }→ 0 :|: v0 >= 0, v1 >= 0, z = v0, z' = v1

Only complete derivations are relevant for the runtime complexity.

(9) CompleteCoflocoProof (EQUIVALENT transformation)

Transformed the RNTS (where only complete derivations are relevant) into cost relations for CoFloCo:

eq(start(V, V1, V11),0,[ge(V, V1, Out)],[V >= 0,V1 >= 0]).
eq(start(V, V1, V11),0,[minus(V, V1, Out)],[V >= 0,V1 >= 0]).
eq(start(V, V1, V11),0,[div(V, V1, Out)],[V >= 0,V1 >= 0]).
eq(start(V, V1, V11),0,[ify(V, V1, V11, Out)],[V >= 0,V1 >= 0,V11 >= 0]).
eq(start(V, V1, V11),0,[if(V, V1, V11, Out)],[V >= 0,V1 >= 0,V11 >= 0]).
eq(ge(V, V1, Out),1,[],[Out = 2,V2 >= 0,V = V2,V1 = 0]).
eq(ge(V, V1, Out),1,[],[Out = 1,V1 = 1 + V3,V3 >= 0,V = 0]).
eq(ge(V, V1, Out),1,[ge(V4, V5, Ret)],[Out = Ret,V1 = 1 + V5,V4 >= 0,V5 >= 0,V = 1 + V4]).
eq(minus(V, V1, Out),1,[],[Out = V6,V6 >= 0,V = V6,V1 = 0]).
eq(minus(V, V1, Out),1,[minus(V7, V8, Ret1)],[Out = Ret1,V1 = 1 + V8,V7 >= 0,V8 >= 0,V = 1 + V7]).
eq(div(V, V1, Out),1,[ge(V9, 1 + 0, Ret0),ify(Ret0, V10, V9, Ret2)],[Out = Ret2,V10 >= 0,V9 >= 0,V = V10,V1 = V9]).
eq(ify(V, V1, V11, Out),1,[],[Out = 1,V1 = V12,V11 = V13,V = 1,V12 >= 0,V13 >= 0]).
eq(ify(V, V1, V11, Out),1,[ge(V14, V15, Ret01),if(Ret01, V14, V15, Ret3)],[Out = Ret3,V = 2,V1 = V14,V11 = V15,V14 >= 0,V15 >= 0]).
eq(if(V, V1, V11, Out),1,[],[Out = 0,V1 = V16,V11 = V17,V = 1,V16 >= 0,V17 >= 0]).
eq(if(V, V1, V11, Out),1,[minus(V18, V19, Ret10),div(Ret10, V19, Ret11)],[Out = 1 + Ret11,V = 2,V1 = V18,V11 = V19,V18 >= 0,V19 >= 0]).
eq(ge(V, V1, Out),0,[],[Out = 0,V20 >= 0,V21 >= 0,V = V20,V1 = V21]).
eq(minus(V, V1, Out),0,[],[Out = 0,V22 >= 0,V23 >= 0,V = V22,V1 = V23]).
eq(ify(V, V1, V11, Out),0,[],[Out = 0,V24 >= 0,V11 = V25,V26 >= 0,V = V24,V1 = V26,V25 >= 0]).
eq(if(V, V1, V11, Out),0,[],[Out = 0,V27 >= 0,V11 = V28,V29 >= 0,V = V27,V1 = V29,V28 >= 0]).
input_output_vars(ge(V,V1,Out),[V,V1],[Out]).
input_output_vars(minus(V,V1,Out),[V,V1],[Out]).
input_output_vars(div(V,V1,Out),[V,V1],[Out]).
input_output_vars(ify(V,V1,V11,Out),[V,V1,V11],[Out]).
input_output_vars(if(V,V1,V11,Out),[V,V1,V11],[Out]).

CoFloCo proof output:
Preprocessing Cost Relations
=====================================

#### Computed strongly connected components
0. recursive : [ge/3]
1. recursive : [minus/3]
2. recursive : [ (div)/3,if/4,ify/4]
3. non_recursive : [start/3]

#### Obtained direct recursion through partial evaluation
0. SCC is partially evaluated into ge/3
1. SCC is partially evaluated into minus/3
2. SCC is partially evaluated into (div)/3
3. SCC is partially evaluated into start/3

Control-Flow Refinement of Cost Relations
=====================================

### Specialization of cost equations ge/3
* CE 14 is refined into CE [23]
* CE 11 is refined into CE [24]
* CE 12 is refined into CE [25]
* CE 13 is refined into CE [26]


### Cost equations --> "Loop" of ge/3
* CEs [26] --> Loop 13
* CEs [23] --> Loop 14
* CEs [24] --> Loop 15
* CEs [25] --> Loop 16

### Ranking functions of CR ge(V,V1,Out)
* RF of phase [13]: [V,V1]

#### Partial ranking functions of CR ge(V,V1,Out)
* Partial RF of phase [13]:
- RF of loop [13:1]:
V
V1


### Specialization of cost equations minus/3
* CE 17 is refined into CE [27]
* CE 15 is refined into CE [28]
* CE 16 is refined into CE [29]


### Cost equations --> "Loop" of minus/3
* CEs [29] --> Loop 17
* CEs [27] --> Loop 18
* CEs [28] --> Loop 19

### Ranking functions of CR minus(V,V1,Out)
* RF of phase [17]: [V,V1]

#### Partial ranking functions of CR minus(V,V1,Out)
* Partial RF of phase [17]:
- RF of loop [17:1]:
V
V1


### Specialization of cost equations (div)/3
* CE 19 is refined into CE [30]
* CE 18 is refined into CE [31,32,33]
* CE 20 is refined into CE [34,35]
* CE 22 is refined into CE [36,37,38,39]
* CE 21 is refined into CE [40,41]


### Cost equations --> "Loop" of (div)/3
* CEs [41] --> Loop 20
* CEs [40] --> Loop 21
* CEs [30] --> Loop 22
* CEs [31] --> Loop 23
* CEs [32,33,34,35,36,37,38,39] --> Loop 24

### Ranking functions of CR div(V,V1,Out)
* RF of phase [20]: [V,V-V1+1]

#### Partial ranking functions of CR div(V,V1,Out)
* Partial RF of phase [20]:
- RF of loop [20:1]:
V
V-V1+1


### Specialization of cost equations start/3
* CE 4 is refined into CE [42,43]
* CE 5 is refined into CE [44,45,46,47,48,49,50]
* CE 6 is refined into CE [51,52,53,54,55]
* CE 7 is refined into CE [56,57,58,59,60,61]
* CE 2 is refined into CE [62]
* CE 3 is refined into CE [63]
* CE 8 is refined into CE [64,65,66,67,68]
* CE 9 is refined into CE [69,70,71]
* CE 10 is refined into CE [72,73,74]


### Cost equations --> "Loop" of start/3
* CEs [65,69,73] --> Loop 25
* CEs [44,45,46,47,52,56,57,59] --> Loop 26
* CEs [42,43,48,49,50,51,53,54,55,58,60,61] --> Loop 27
* CEs [63] --> Loop 28
* CEs [62,64,66,67,68,70,71,72,74] --> Loop 29

### Ranking functions of CR start(V,V1,V11)

#### Partial ranking functions of CR start(V,V1,V11)


Computing Bounds
=====================================

#### Cost of chains of ge(V,V1,Out):
* Chain [[13],16]: 1*it(13)+1
Such that:it(13) =< V

with precondition: [Out=1,V>=1,V1>=V+1]

* Chain [[13],15]: 1*it(13)+1
Such that:it(13) =< V1

with precondition: [Out=2,V1>=1,V>=V1]

* Chain [[13],14]: 1*it(13)+0
Such that:it(13) =< V1

with precondition: [Out=0,V>=1,V1>=1]

* Chain [16]: 1
with precondition: [V=0,Out=1,V1>=1]

* Chain [15]: 1
with precondition: [V1=0,Out=2,V>=0]

* Chain [14]: 0
with precondition: [Out=0,V>=0,V1>=0]


#### Cost of chains of minus(V,V1,Out):
* Chain [[17],19]: 1*it(17)+1
Such that:it(17) =< V1

with precondition: [V=Out+V1,V1>=1,V>=V1]

* Chain [[17],18]: 1*it(17)+0
Such that:it(17) =< V1

with precondition: [Out=0,V>=1,V1>=1]

* Chain [19]: 1
with precondition: [V1=0,V=Out,V>=0]

* Chain [18]: 0
with precondition: [Out=0,V>=0,V1>=0]


#### Cost of chains of div(V,V1,Out):
* Chain [[20],24]: 6*it(20)+8*s(3)+4*s(7)+2*s(10)+1*s(21)+5
Such that:aux(1) =< 1
aux(7) =< V-V1+1
aux(3) =< V1
aux(10) =< V
s(3) =< aux(1)
s(7) =< aux(10)
s(10) =< aux(3)
aux(5) =< aux(10)
it(20) =< aux(10)
aux(5) =< aux(7)
it(20) =< aux(7)
s(21) =< aux(5)

with precondition: [V1>=1,Out>=1,V+1>=Out+V1]

* Chain [[20],21,24]: 6*it(20)+9*s(3)+4*s(10)+1*s(21)+2*s(22)+10
Such that:aux(12) =< 1
aux(6) =< V
aux(7) =< V-V1+1
aux(13) =< V1
aux(14) =< V-V1
s(3) =< aux(12)
s(10) =< aux(13)
aux(5) =< aux(6)
it(20) =< aux(6)
s(23) =< aux(6)
aux(5) =< aux(7)
it(20) =< aux(7)
aux(5) =< aux(14)
it(20) =< aux(14)
s(23) =< aux(14)
s(21) =< aux(5)
s(22) =< s(23)

with precondition: [V1>=1,Out>=2,V+2>=2*V1+Out]

* Chain [24]: 8*s(3)+2*s(7)+2*s(10)+5
Such that:aux(1) =< 1
aux(2) =< V
aux(3) =< V1
s(3) =< aux(1)
s(7) =< aux(2)
s(10) =< aux(3)

with precondition: [Out=0,V>=0,V1>=0]

* Chain [23]: 2
with precondition: [V1=0,Out=0,V>=0]

* Chain [22]: 3
with precondition: [V1=0,Out=1,V>=0]

* Chain [21,24]: 9*s(3)+4*s(10)+10
Such that:aux(12) =< 1
aux(13) =< V1
s(3) =< aux(12)
s(10) =< aux(13)

with precondition: [Out=1,V1>=1,V>=V1]


#### Cost of chains of start(V,V1,V11):
* Chain [29]: 16*s(59)+7*s(60)+34*s(67)+6*s(78)+1*s(80)+2*s(81)+6*s(84)+1*s(85)+10
Such that:s(70) =< V-V1
s(73) =< V-V1+1
aux(19) =< 1
aux(20) =< V
aux(21) =< V1
s(60) =< aux(20)
s(59) =< aux(21)
s(67) =< aux(19)
s(77) =< aux(20)
s(78) =< aux(20)
s(79) =< aux(20)
s(77) =< s(73)
s(78) =< s(73)
s(77) =< s(70)
s(78) =< s(70)
s(79) =< s(70)
s(80) =< s(77)
s(81) =< s(79)
s(83) =< aux(20)
s(84) =< aux(20)
s(83) =< s(73)
s(84) =< s(73)
s(85) =< s(83)

with precondition: [V>=0,V1>=0]

* Chain [28]: 1
with precondition: [V=1,V1>=0,V11>=0]

* Chain [27]: 2*s(86)+39*s(87)+84*s(92)+12*s(101)+12*s(113)+2*s(115)+4*s(116)+12*s(119)+2*s(120)+14
Such that:aux(28) =< 1
aux(29) =< V1
aux(30) =< V1-2*V11
aux(31) =< V1-2*V11+1
aux(32) =< V1-V11
aux(33) =< V11
s(86) =< aux(29)
s(87) =< aux(33)
s(92) =< aux(28)
s(101) =< aux(32)
s(112) =< aux(32)
s(113) =< aux(32)
s(114) =< aux(32)
s(112) =< aux(31)
s(113) =< aux(31)
s(112) =< aux(30)
s(113) =< aux(30)
s(114) =< aux(30)
s(115) =< s(112)
s(116) =< s(114)
s(118) =< aux(32)
s(119) =< aux(32)
s(118) =< aux(31)
s(119) =< aux(31)
s(120) =< s(118)

with precondition: [V=2,V1>=0,V11>=0]

* Chain [26]: 24*s(158)+4*s(159)+9
Such that:aux(35) =< 1
aux(36) =< V1
s(158) =< aux(35)
s(159) =< aux(36)

with precondition: [V=2,V11=0,V1>=0]

* Chain [25]: 3
with precondition: [V1=0,V>=0]


Closed-form bounds of start(V,V1,V11):
-------------------------------------
* Chain [29] with precondition: [V>=0,V1>=0]
- Upper bound: 23*V+16*V1+44
- Complexity: n
* Chain [28] with precondition: [V=1,V1>=0,V11>=0]
- Upper bound: 1
- Complexity: constant
* Chain [27] with precondition: [V=2,V1>=0,V11>=0]
- Upper bound: 2*V1+39*V11+98+nat(V1-V11)*44
- Complexity: n
* Chain [26] with precondition: [V=2,V11=0,V1>=0]
- Upper bound: 4*V1+33
- Complexity: n
* Chain [25] with precondition: [V1=0,V>=0]
- Upper bound: 3
- Complexity: constant

### Maximum cost of start(V,V1,V11): 2*V1+30+max([23*V+14*V1+11,nat(V11)*39+65+nat(V1-V11)*44])+3
Asymptotic class: n
* Total analysis performed in 486 ms.

(10) BOUNDS(1, n^1)